<?php
/**
*btc列表
*/

require_once 'common.inc.php';
!in_array('1',$larr)&&adminmsg('你没有被赋予操作该项的权限！');
$matches=parse_url($_SERVER['HTTP_REFERER']);
//$url=$matches['scheme'].'://'.$matches['host'].'/';

$dsarray=array('dsip', 'ifdispatch' , 'ifiopatch' , 'ifsyspatch', 'ifbtcpatch',  'ifoptimze' , 'iftimepatch' , 'iftcpmd5' , 'ifpassport' , 'iftcptrans'  ,'iffcfcalg',  'ifadpatch' , 'ifdatapatch' , 'ifsetpatch' );

if('list'==$action)
{
	$action='doedit';
	$btclist=array();
	$query=$db->query("select * from msys_ds ");
   	$dsdb=$db->fetch_array($query);
	
	if($dsdb)
	{	
		if($dsdb['ifdispatch']=='1')
		{
			$ck_ifdispatch="checked=true";
		}else{
			$ck_fifdispatch="checked=true";
		}
		if ($dsdb['ifiopatch']=='1'){
			$ck_ifiopatch="checked=true";
		}else{
			$ck_fifiopatch="checked=true";
		}
		if ($dsdb['ifsyspatch']=='1'){
			$ck_ifsyspatch="checked=true";
		}else{
			$ck_fifsyspatch="checked=true";
		}
		if ($dsdb['ifbtcpatch']=='1'){
			$ck_ifbtcpatch="checked=true";
		}else{
			$ck_fifbtcpatch="checked=true";
		}
		if ($dsdb['ifoptimze']=='1'){
			$ck_ifoptimze="checked=true";
		}else{
			$ck_fifoptimze="checked=true";
		}
		if ($dsdb['iftimepatch']=='1'){
			$ck_iftimepatch="checked=true";
		}else{
			$ck_fiftimepatch="checked=true";
		}
		if ($dsdb['iftcpmd5']=='1'){
			$ck_iftcpmd5="checked=true";
		}else{
			$ck_fiftcpmd5="checked=true";
		}
		if ($dsdb['ifpassport']=='1'){
			$ck_ifpassport="checked=true";
		}else{
			$ck_fifpassport="checked=true";
		}
		if ($dsdb['iftcptrans']=='1'){
			$ck_iftcptrans="checked=true";
		}else{
			$ck_fiftcptrans="checked=true";
		}
		if ($dsdb['iffcfcalg']=='1'){
			$ck_iffcfcalg="checked=true";
		}else{
			$ck_fiffcfcalg="checked=true";
		}
		if ($dsdb['ifadpatch']=='1'){
			$ck_ifadpatch="checked=true";
		}else{
			$ck_fifadpatch="checked=true";
		}
		if ($dsdb['ifdatapatch']=='1'){
			$ck_ifdatapatch="checked=true";
		}else{
			$ck_fifdatapatch="checked=true";
		}
		if ($dsdb['ifsetpatch']=='1'){
			$ck_ifsetpatch="checked=true";
		}else{
			$ck_fifsetpatch="checked=true";
		}
	}
	
	$dsid=$dsdb['dsid'];
	include_once MCC_ROOT.'/templates/msystem/dsadd.htm';
}
elseif('doedit'==$action)
{
	
	if($dsid)
	{
		$dsid=intval($dsid);
		if($dsid)
		{
			$first=0;
			$query=$db->query("select * from msys_ds where dsid='$dsid'");
			$tempdb=$db->fetch_array($query);
	
			$sql='';
			foreach($_POST as $key=>$value)
			{
				if(isset($tempdb[$key])&&$value!=$tempdb[$key]&&in_array($key,$dsarray))
				{
					if(!$first)
					{
						$sql.="$key='$value'";
						$first=1;
					}
					else
					{
						$sql.=" ,$key='$value'";
					}	
				}
			}
			//$sql=substr($sql,0,-1);
			if($first)
			{
				$sql="update msys_ds set $sql where dsid='$dsid'";
				//print $sql;
				$sql&&$db->query($sql);
			}
			adminmsg('DS设置成功','ds.inc.php?action=list');	
		}
	}
	else
	{
		$sql='insert into msys_ds '	;
		$first=0;
    	foreach($_POST as $key=>$value)
		{
			if($first)
			{
				if(in_array($key,$dsarray))
				{
					$sqlkey.=",$key";
					$sqlvalue.=",'$value'";
				}
			}
			else
			{
		    	if(in_array($key,$dsarray))
				{
					$sqlkey=$sql. "( $key ";
					$sqlvalue=" values ('$value' ";
					$first=1;
				}
			}	
		}
		$sql=$sqlkey.')'.$sqlvalue.')';
		//print $sql;
    	$db->query($sql);
		$dsid=$db->insert_id();
		adminmsg('DS设置成功','ds.inc.php?action=list');		
	}
}
?>